import {defineStore} from "pinia";

export const useAuthStore = defineStore('auth', {
    state: () => ({
        token: '',  // 存储 token
    }),
    actions: {
        // 设置 token
        setToken(token) {
            this.token = token
        },
        // 获取 token
        getToken() {
            return this.token
        },
        // 清除 token
        clearToken() {
            this.token = ''
        }
    },
    persist: {
        enabled: true,
        strategies: {
            key: 'auth',
            storage: sessionStorage,
            paths: ['token']
        }
    }
})
